﻿using UnityEngine;
using System.Collections;

public class Missile : MonoBehaviour {

    public float StantardSpeed = 800;
    public int Power;

    protected void Awake()
    {
        mTransform = transform;
    }

    protected void Update()
    {
        var position = mTransform.localPosition + mDirection * StantardSpeed * Time.deltaTime;
        if (position.y > 960)
        {
            Destroy(gameObject);
            return;
        }
        mTransform.localPosition = position;
    }

    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.tag == "Enemy" && col.GetComponent<Flyer>().IsAlive)
        {
            Destroy(gameObject);
            col.GetComponent<Flyer>().ReceiveDamage(Power);
        }
            
    }

    private readonly Vector3 mDirection = Vector3.up;
    private Transform mTransform;
}
